package com.springmvc.demo.controller;


import com.springmvc.demo.model.UserInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

//@RestController
@Controller
@RequestMapping("/return")
public class ReturnController {

    // 返回页面
    @ResponseBody
    @RequestMapping("/r1")
    public String r1() {
        return "/index.html";
    }

    // 返回 json
    @ResponseBody
    @RequestMapping("/r4")
    public String r4() {
        UserInfo userInfo = new UserInfo(18, 18, "lpy");
        return userInfo.toString();
    }

    @ResponseBody
    @RequestMapping("/r5")
    public Map<String, String> r5() {
        HashMap map = new HashMap<>();
        map.put("k1", "v1");
        return map;
    }

    @RequestMapping("/r6")
    public String r6() {
        return "/a.js";
    }

    @RequestMapping("/r7")
    public String r7() {
        return "/b.css";
    }

    // 设置状态码
    @ResponseBody
    @RequestMapping("/r8")
    public String r8(HttpServletResponse response) {
        response.setStatus(401);
        return "设置状态码成功";
    }

    // 设置content-type
    @ResponseBody
    @RequestMapping(value = "/r9", produces = "application/json; charset=utf8")
    public String r9() {
        return "{\"llt\" : \"2569\"}";
    }

    // 自定义 Header
    @ResponseBody
    @RequestMapping(value = "/r10")
    public String r10(HttpServletResponse response) {
        response.setHeader("myHeader", "HeaderValue");
        return "返回成功";
    }


}
